"""CRM_CWMK_YSK_009，验证添加收款单功能_合法添加"""

from selenium.webdriver.common.by import By
from page.base_page_helin import BasePage

class AddFkdPage(BasePage):
     # 登录定位器
    username_locator = (By.NAME,'name')
    password_locator = (By.NAME, 'password')
    submit_locator = (By.NAME,"submit")

    # 进入添加应收款页面定位器
    cw_locator=(By.LINK_TEXT,"财务")
    yfk_locator=(By.LINK_TEXT,"应付款")
    tjfkd_locator=(By.LINK_TEXT,"添加付款单")

    # 添加付款单定位器
    fzr_locator=(By.ID,"owner_name")
    xzfzr_table_locator=(By.XPATH,'//*[@id="d_content"]')
    fzrok_locator=(By.XPATH,"/html/body/div[8]/div[3]/div/button[1]")

    fkd_locator=(By.ID,'payables')
    xzyfk_table_locator=(By.XPATH,'//*[@id="data"]')
    yfkok_locator=(By.XPATH,"/html/body/div[7]/div[3]/div/button[1]")
    fkje_locator=(By.ID,"money")
    fksj_locator=(By.XPATH,'//*[@id="pay_time"]')

    zt_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]')
    ms_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tbody/tr[8]/td[2]/textarea')
    bcfkd_locator=(By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')

    def click_cw(self):
        # 进入添加付款单页面
        self.driver.find_element(*self.cw_locator).click()

    def click_yfk(self):
        self.driver.find_element(*self.yfk_locator).click()

    def click_tjfkd(self):
        self.driver.find_element(*self.tjfkd_locator).click()

    def add_fzr(self):
        self.driver.find_element(*self.fzr_locator).click()
        tbody=self.driver.find_element(*self.xzfzr_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text=="小明":
                tds[0].click()
                break
        self.driver.find_element(*self.fzrok_locator).click()

    def add_fkd(self):
        self.driver.find_element(*self.fkd_locator).click()
        tbody=self.driver.find_element(*self.xzyfk_table_locator)
        trs=tbody.find_elements(By.TAG_NAME,"tr")
        for tr in trs:
            tds=tr.find_elements(By.TAG_NAME,"td")
            if tds[1].text=="买电脑":
                tds[0].find_element(By.CSS_SELECTOR,'input[name="payables"]').click()
                break
        self.driver.find_element(*self.yfkok_locator).click()

    def add_fkje(self,fkje):
        self.driver.find_element(*self.fkje_locator).clear()
        self.driver.find_element(*self.fkje_locator).send_keys(fkje)

    def add_fksj(self,fksj):
        self.driver.find_element(*self.fksj_locator).send_keys(fksj)

    def add_zt(self):
        self.driver.find_elements(*self.zt_locator)[0].click()

    def add_ms(self,ms):
        self.driver.find_element(*self.ms_locator).send_keys(ms)

    def add_bcfkd(self):
        self.driver.find_element(*self.bcfkd_locator).click()
